﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package Display.hud.components {
    import flash.events.*;
    import Events.*;
    import Display.DialogUI.*;
    import org.aswing.*;
    import Classes.*;
    import Classes.util.*;
    import __AS3__.vec.*;
    import flash.filters.*;
    import Display.*;
    import Display.MarketUI.*;
    import Classes.orders.*;
    import Modules.franchise.data.*;
    import Modules.quest.Display.*;
    import Display.aswingui.*;

    public class HUDFranchiseRequestComponent extends HUDComponent {

        private static const MIN_LEVEL:int = 6;

        private var m_pendingFranchiseName:String;

        public function HUDFranchiseRequestComponent(){
            this.m_pendingFranchiseName = null;
            super();
        }
        override public function isVisible():Boolean{
            var _local1 = !((Global.getVisiting() == GameWorld.CITY_SAM_OWNER_ID));
            if (_local1){
                _local1 = (((((Global.franchiseManager.eligibleFranchises.length > 0)) && ((Global.player.level >= MIN_LEVEL)))) && (BuyLogic.canAcceptFranchiseRequests(Global.getVisiting())));
            };
            return (_local1);
        }
        private function getPendingFranchiseType():String{
            var _local4:OwnedFranchiseData;
            var _local1:String;
            var _local2:Boolean;
            var _local3:Vector.<OwnedFranchiseData> = Global.franchiseManager.getPendingSentFranchiseOrders();
            for each (_local4 in _local3) {
                _local2 = _local4.hasLocation(Global.getVisiting());
                if (_local2){
                    _local1 = _local4.franchiseType;
                    break;
                };
            };
            return (_local1);
        }
        override protected function buildComponent():void{
            var _local1:Component;
            var _local2:GameSprite;
            var _local3:String;
            var _local4:String;
            var _local5:String;
            this.m_pendingFranchiseName = this.getPendingFranchiseType();
            if (this.m_pendingFranchiseName){
                _local3 = Global.player.getFriendFirstName(Global.getVisiting());
                _local4 = (this.m_pendingFranchiseName) ? Global.franchiseManager.getFranchiseName(this.m_pendingFranchiseName, Global.player.uid) : null;
                _local2 = new GameSprite();
                _local2.addChild(new EmbeddedArt.franchiseRequestPendingIcon());
                _local5 = ZLoc.t("Main", "pendingFranchiseTooltip", {friendName:_local3});
                _local5 = (_local5 + "\n");
                _local5 = (_local5 + ZLoc.t("Main", "pendingFranchiseTooltipLine3"));
                _local2.toolTip = _local5;
                _local1 = new AssetPane(_local2);
                _local1.addEventListener(MouseEvent.CLICK, this.onPendingClick, false, 0, true);
            } else {
                _local2 = new GameSprite();
                _local2.addChild(new EmbeddedArt.franchiseRequestIcon());
                ButtonManager.buttonize(_local2, null, EffectsUtil.getGlowEffectByAssignment("sidebar"));
                _local2.toolTip = ZLoc.t("Main", "requestFranchiseTooltip");
                _local1 = new AssetPane(_local2);
                _local1.addEventListener(MouseEvent.CLICK, this.onClick, false, 0, true);
            };
            _local1.addEventListener(MouseEvent.MOUSE_OVER, this.onButtonMouseOver);
            _local1.addEventListener(MouseEvent.MOUSE_OUT, this.onButtonMouseOut);
            m_jPanel = ASwingHelper.makeSoftBoxJPanelVertical(SoftBoxLayout.LEFT, 0);
            m_jPanel.append(_local1);
        }
        private function onButtonMouseOut(_arg1:MouseEvent):void{
            this.filters = null;
        }
        private function onButtonMouseOver(_arg1:MouseEvent):void{
            var _local2:GlowFilter = new GlowFilter(EmbeddedArt.HOVER_GLOW_COLOR, 1, 8, 8, 5);
            this.filters = [_local2];
        }
        override public function refresh(_arg1:Boolean):void{
            super.refresh(_arg1);
            if (this.getPendingFranchiseType() != this.m_pendingFranchiseName){
                this.buildComponent();
                showComponent();
            };
        }
        private function onPendingClick(_arg1:Event):void{
            this.m_pendingFranchiseName = this.getPendingFranchiseType();
            var _local2:String = Global.player.getFriendFirstName(Global.getVisiting());
            var _local3:String = (this.m_pendingFranchiseName) ? Global.franchiseManager.getFranchiseName(this.m_pendingFranchiseName, Global.player.uid) : null;
            this.filters = null;
            UI.displayMessage(ZLoc.t("Dialogs", "lotOrder_cancel_message", {
                friendName:_local2,
                franchiseName:_local3
            }), GenericDialogView.TYPE_YESNO, this.cancelLotOrder);
        }
        private function cancelLotOrder(_arg1:GenericPopupEvent):void{
            if (_arg1.button != GenericDialogView.YES){
                return;
            };
            var _local2:LotOrder = Global.franchiseManager.getPendingSentFranchiseOrderForNeighbor(Global.getVisiting());
            Global.world.citySim.lotManager.cancel(_local2);
        }
        private function onClick(_arg1:Event):void{
            UI.displayCatalog("business", null);
            Global.franchiseManager.placementMode = true;
        }

    }
}//package Display.hud.components 
